package demo10;



public class SparseStringArraySearch {
    public Search createSearch(){
        return new Search();
    }

    public class Search{
        public int binarySearchPos(String[] arr, String val){

            return binarySearchPos(arr,val,0,arr.length);

        }
        public int binarySearchPos(String[] arr, String val, int low , int high){
            // firstly , should  dynamic compute the middle and  low and high ,
            if(low<=high) {
                int middle = (low + high) / 2;
                //  when the arr[mid]="" , change pos to the the closest no-""
                if(arr[middle].compareTo(val)>0 ){
                    return binarySearchPos (arr,val,low,middle-1 );
                }else if (arr[middle].compareTo(val)<0){
                    return binarySearchPos(arr,val,middle+1,high  );
                }else{
                    return middle;
                }
            }
            return -1;
        }

    }
}
